package net.hn.hnms.biz.cockpit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.hn.hnms.biz.cockpit.domain.AutomaticSystem;
import net.hn.hnms.biz.cockpit.domain.WorkflowSystem;
import net.hn.hnms.biz.cockpit.domain.vo.AutomaticSysVo;
import net.hn.hnms.biz.cockpit.mapper.AutomaticSystemMapper;
import net.hn.hnms.biz.cockpit.service.IAutomaticSystemService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class AutomaticSystemServiceImpl extends ServiceImpl<AutomaticSystemMapper, AutomaticSystem> implements IAutomaticSystemService {

    @Override
    public List<AutomaticSysVo> getAutomaticSysList(String mineCode) {
        List<AutomaticSysVo> result = Collections.emptyList();
        List<AutomaticSystem> automaticSystems = baseMapper.selectList(new LambdaQueryWrapper<AutomaticSystem>().eq(AutomaticSystem::getMineCode, mineCode));
        if (CollectionUtils.isNotEmpty(automaticSystems)){
            Map<String, List<AutomaticSystem>> collect = automaticSystems.stream().collect(Collectors.groupingBy(AutomaticSystem::getSysCode));
            result = collect.entrySet().stream().map(entry -> new AutomaticSysVo(entry.getKey(),entry.getValue().get(0).getSysName(), entry.getValue().size())).collect(Collectors.toList());
        }
        return result;
    }


}
